// components/camp-other/camp-other.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    projectStatus: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    projectStatus: false,
    addList: [], //整体数据
    campid: "",
    scenicid: "", //景点id
    introduce: "",
    imageUrl: "",
    projectname: '',
    memberprice: '',
    originalprice: '',
  },
  lifetimes: {
    ready() {

    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 绑定营地介绍
    changeIntroduce(e) {
      this.setData({
        introduce: e.detail.value
      })
    },
    //重置数据
    resetData() {
      this.setData({
        campid: "",
        projectname: '',
        memberprice: '',
        originalprice: '',
        introduce: "",
        imageUrl: "",
      })
    },
    //添加虚拟数据
    addData(e) {
      const object = {
        projectname: e.detail.value.projectname,
        memberprice: Number(e.detail.value?.memberprice),
        originalprice: Number(e.detail.value.originalprice),
        introduce: this.data.introduce,
      }
      console.log("object",object);
      var isEmpty = true;
      Object.keys(object).forEach(function (x) {
        if (object[x] === null || object[x] === "") {
          isEmpty = false;
        }
      });
      if (isEmpty) {
        this.data.addList.push({
          projectname: e.detail.value.projectname,
          memberprice: Number(e.detail.value?.memberprice),
          originalprice: Number(e.detail.value.originalprice),
          introduce: this.data.introduce,
        })
        this.resetData();
        this.onClose();
        this.triggerEvent("sendData", this.data.addList)
      } else {
        wx.showToast({
          title: "信息未填写完整",
          icon: "error",
          duration: 1500
        })
      }

      // console.log(instance.globalData.campData)
      console.log(this.data.addList);
    },
    onClose() {
      this.resetData()
      this.setData({
        projectStatus: false
      })
    },
  }
})